//  @author: ideawu
//  @link: https://github.com/ideawu/Objective-C-RSA
//
//  RDeliveryRSA.h
//  RDelivery
//
//  Created by mellow on 2021/9/10.
//  Copyright (c) 2021 Tencent. All rights reserved.
//

#ifndef RDeliveryRSA_h
#define RDeliveryRSA_h

#import <Foundation/Foundation.h>

@interface RDeliveryRSA : NSObject

extern NSString *rdelivery_base64_encode_data(NSData *data);
extern NSData *rdelivery_base64_decode(NSString *str);


// return base64 encoded string
+ (NSString *)encryptString:(NSString *)str
                  publicKey:(NSString *)pubKey
                      error:(NSError **)error;
// return base64 encoded string
+ (NSString *)encryptString:(NSString *)str
                 privateKey:(NSString *)privKey
                      error:(NSError **)error;

// decrypt base64 encoded string, convert result to string(not base64 encoded)
+ (NSString *)decryptString:(NSString *)str
                  publicKey:(NSString *)pubKey
                      error:(NSError **)error;

+ (NSString *)decryptString:(NSString *)str
                 privateKey:(NSString *)privKey
                      error:(NSError **)error;

#if TARGET_OS_IPHONE
// return raw data
+ (NSData *)encryptData:(NSData *)data
              publicKey:(NSString *)pubKey
                  error:(NSError **)error;
// return raw data
+ (NSData *)encryptData:(NSData *)data
             privateKey:(NSString *)privKey
                  error:(NSError **)error;

+ (NSData *)decryptData:(NSData *)data
              publicKey:(NSString *)pubKey
                  error:(NSError **)error;

+ (NSData *)decryptData:(NSData *)data
             privateKey:(NSString *)privKey
                  error:(NSError **)error;
#endif

#if TARGET_OS_OSX

+ (NSData *)encryptData:(NSData *)data withPrivateKey:(SecKeyRef)key error:(NSError **)errorPtr;
+ (NSData *)decryptData:(NSData *)encryptedData withPublicKey:(SecKeyRef)key error:(NSError **)errorPtr;

+ (NSData *)encryptData:(NSData *)data withPublicKey:(SecKeyRef)key error:(NSError **)errorPtr;
+ (NSData *)decryptData:(NSData *)encryptedData withPrivateKey:(SecKeyRef)key error:(NSError **)errorPtr;

#endif

@end

#endif /* RDeliveryRSA_h */
